﻿#pragma once
#include <fstream>
#include <opencv2/opencv.hpp>
namespace wq{
	using namespace std;
	using namespace cv;
	const char* IMG_PNG = "D://big_logo.pn.png";
	const char* VIDEO_MP4 = "D://video.mp4";
	int test1() {
		cout << "Hello World111" << endl;
		Mat img1 = imread(IMG_PNG);
		Mat img2 = Mat(img1.size(), img1.type());

		if (img1.empty()) return -1;

		blur(img1, img2, Size(5, 5), Point(-1, -1), 4);
		namedWindow("img1 Window", CV_WINDOW_AUTOSIZE);
		imshow("img1 Window", img1);
		namedWindow("img2 Window", CV_WINDOW_AUTOSIZE);
		imshow("img2 Window", img2);
		waitKey(0);
		destroyAllWindows();
		return 0;
	}

	int test2() {
		VideoCapture vCap;
		vCap.open(VIDEO_MP4);
		Mat frame;
		namedWindow("video cap");
		while (true) {
			vCap >> frame;
			if (frame.empty()) break;
			imshow("video cap",frame);
			if (27 == waitKey(23)) break;
		}
		destroyWindow("video cap");
		return 0;
	}


	VideoCapture g_vCap;
	bool g_isRunMode = true;
	int pos;
	void onTrackBarSlide(int pos,void *) {
		g_vCap.set(CAP_PROP_POS_FRAMES, pos);
	}

	int test3() {
		const char* WINDOW_NAME = "vCap Window";
		const char* TRACKBAR_NAME = " vCap Track";
		namedWindow(WINDOW_NAME);
		g_vCap.open(VIDEO_MP4);
		int width = g_vCap.get(CAP_PROP_FRAME_WIDTH);
		int height = g_vCap.get(CAP_PROP_FRAME_HEIGHT);
		int count = g_vCap.get(CAP_PROP_FRAME_COUNT);
		cout << WINDOW_NAME << " width = " << width << "px" << endl;
		cout << WINDOW_NAME << " height = " << height << "px" << endl;
		createTrackbar(TRACKBAR_NAME, WINDOW_NAME, &pos, count,onTrackBarSlide);
		Mat frame;
		bool isStepMode = false;
		while (true) {
			if(g_isRunMode){
				g_vCap >> frame;
				if (frame.empty()) {
					break;
				}
				//GaussianBlur(frame,frame,Size(5,5),3,3,4);//CPU使用率极高
				int currentPos = g_vCap.get(CAP_PROP_POS_FRAMES);
				setTrackbarPos(TRACKBAR_NAME,WINDOW_NAME,currentPos);
				imshow(WINDOW_NAME, frame);
				if (isStepMode) {
					g_isRunMode = false;
				}
			}
			char c = waitKey(33);
			if ('s' == c) {
				g_isRunMode = true;
				isStepMode = true;
			}
			if ('r' == c) {
				g_isRunMode = true;
				isStepMode = false;
			}
			if (27 == c) {
				break;
			}
		}
		return 0;
	}



	const int MAX = 10;
	int printArr2(int a[MAX][MAX]) {
		for (int i = 0; i < MAX; i++) {
			for (int j = 0; j < MAX; j++) {
				cout << a[i][j] << "  ";
			}
			cout << endl;
		}
		return 0;
	}
	int otherTest() {
		int a[MAX][MAX];
		int x,y,i=1,c;//x y 为下表，i为赋值，c为下表和规律
		for (c = 0; c < MAX*2;c++) {
			for (x = 0; x < MAX; x++) {
				for (y = 0; y < MAX; y++) {
					if (x + y == c) {
						a[y][x] = i++;
						break;
					}
				}
			}
		}
		printArr2(a);
		cin >> i;
		return 0;
	}
	
	int otherTest2() {
		ifstream in;

	}

	int lesson2() {
		return otherTest();
	}
}